﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PropController : MonoBehaviour
{
    public Text score;
    PlayerController player;

    bool isBig;
    float bigTime;
    Vector3 normalSize;
    Vector3 bigSiez;
    int normaAtk;
    int bigAtk;
    void Start()
    {
        player = transform.parent.GetComponent<PlayerController>();
        normalSize = transform.parent.localScale;
        bigSiez = normalSize * 3;
        normaAtk = player.atk;
        bigAtk = normaAtk * 2;
    }

    void Update()
    {
        if (isBig)
        {
            player.atk = bigAtk;
            transform.parent.localScale = bigSiez;
            bigTime += Time.deltaTime;
            if (bigTime >= 5)
            {
                isBig = false;
                player.atk = normaAtk;
                bigTime = 0;
                transform.parent.localScale = normalSize;
            }
        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Item_Koban")
        {
            Destroy(other.gameObject);
            score.text = "Score  " + (int.Parse(score.text.Split(' ')[2]) + 100).ToString().PadLeft(6, '0');
        }

        if (other.gameObject.tag == "Item_Hyoutan")
        {
            Destroy(other.gameObject);
            player.hp = player.maxHp;
        }

        if (other.gameObject.tag == "Item_Makimono")
        {
            Destroy(other.gameObject);
            isBig = true;
        }
    }
}
